package com.example.async;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.Executors;

@Slf4j
@Configuration
@EnableScheduling
public class ScheduleTask implements SchedulingConfigurer {

//    @Scheduled(cron = "0/5 * * * * *")
    public void task1() {
        log.info("thread {}, task1", Thread.currentThread().getName());
    }

//    @Scheduled(cron = "0/7 * * * * *")
    public void task2() {
        log.info("thread {}, task2", Thread.currentThread().getName());
    }

    /**
     * 指定scheduler的任务执行线程池
     * @param taskRegistrar the registrar to be configured.
     */
    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.setScheduler(Executors.newScheduledThreadPool(20));
    }
}
